package com.ziyun.erp.web.modules.push.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.freightages.service.SdbEctoolsRegionsService;
import com.ziyun.erp.modules.supp.entity.PopSysUserEntity;
import io.renren.common.validator.ValidatorUtils;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.push.entity.ErpGoodsPushEntity;
import com.ziyun.erp.modules.push.service.ErpGoodsPushService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 采购商品APP推送记录表
 *
 * @author 'gaosheng'
 * @email
 * @date 2019-02-16 10:50:14
 */
@RestController
@RequestMapping("push/erpgoodspush")
public class ErpGoodsPushController {

    @Autowired
    private ErpGoodsPushService erpGoodsPushService;
    @Autowired
    private SdbEctoolsRegionsService sdbEctoolsRegionsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = erpGoodsPushService.queryPage(params);
        List<String> result = sdbEctoolsRegionsService.queryRegionsList(); //查询省市区
        Map<String, Object> map = new HashMap<>();
        map.put("list", result);
        return R.ok().put("page", page).put("list", map);
    }

    /**
     * POP会员列表
     */
    @RequestMapping("/getPopUserList")
    public R getPopUserList(@RequestParam Map<String, Object> params) {
        List<PopSysUserEntity> list = erpGoodsPushService.getPopUserList(params);

        return R.ok().put("list", list);
    }

    /**
     * 保存信息并推送
     */
    @RequestMapping("/saveInfo")
    public R saveInfo(@RequestBody ErpGoodsPushEntity erpGoodsPush) {
        ValidatorUtils.validateEntity(erpGoodsPush);
        Long userId = UserUtils.getCurentUser().getUserId();
        erpGoodsPush.setCreateName(userId.toString());
        erpGoodsPushService.saveInfo(erpGoodsPush);

        return R.ok();
    }

}
